﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using KingRoad.EPM.Web.Areas.PersonnelLog.ViewModels;
using KingRoad.EPM.Web.Areas.PersonnelLog.PersonnelLogFramework.Common;
using System.Dynamic;
using KingRoad.EPM.PersonnelLogEntity.Model;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System.IO;
using System.Text;
using NPOI.HSSF.UserModel;
using System.Data;
//using KingRoad.EPM.Web.Areas.SafetyConstruction.SafetyConstructionFramework.Common;


namespace KingRoad.EPM.Web.Areas.PersonnelLog.Controllers
{
    public class PlmConstructionPersonnelController : BaseController
    {
        public const string RYGL_SGRY = "RYGL_SGRY";
        /// <summary>
        /// 施工人员信息管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ConstructionPersonnelIndex()
        {
            return View();
        }
        /// <summary>
        /// 施工人员列表
        /// </summary>
        /// <returns></returns>
        public ActionResult ConstructionPersonnelList(string Section)
        {
            ViewBag.Section = Section;
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = 1;
            //每页多少条
            ViewBag.numPerPage = 20;

            int tempTotalRecord = 0;
            var allList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(1, ALL_RECORD_ITEMS, "Pi_UpdateTime", out tempTotalRecord, "Pi_SectionName='" + Section + "'");
            SetSectionValue(RYGL_SGRY, allList);



            var consPersonnelList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(ViewBag.pageNum, ViewBag.numPerPage, "Pi_UpdateTime", out totalRecord, "Pi_SectionName='" + Section + "'");
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            return View(new PlmPersonnelinfoViewModel { ThePersonnelinfoList = consPersonnelList });
        }

        /// <summary>
        /// 施工人员信息-列表(分页提交)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SplitPage()
        {
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = Convert.ToInt32(Request.Form["pageNum"]);
            //每页多少条
            ViewBag.numPerPage = Convert.ToInt32(Request.Form["numPerPage"]);
            ViewBag.iput_name = Request.Form["iput_name"];
            ViewBag.iput_post = Request.Form["iput_post"];
            ViewBag.Section = Request.Form["input_section"];
            ViewBag.iput_professsional = Request.Form["iput_professsional"];
            string sql = " 1=1 ";
            if (ViewBag.iput_name != "")
                sql += " and Pi_Name like '%" + ViewBag.iput_name + "%' ";
            if (ViewBag.iput_post != "")
                sql += " and Pi_Post like '%" + ViewBag.iput_post + "%' ";
            if (ViewBag.iput_professsional != "")
                sql += " and Pi_Professional like '%" + ViewBag.iput_professsional + "%' ";
            if (ViewBag.Section != "")
                sql += " and Pi_SectionName= '" + ViewBag.Section + "' ";

            int tempTotalRecord = 0;
            var allList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(1, ALL_RECORD_ITEMS, "Pi_UpdateTime", out tempTotalRecord, sql);
            SetSectionValue(RYGL_SGRY, allList);

            var consPersonnelList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(ViewBag.pageNum, ViewBag.numPerPage, "Pi_UpdateTime", out totalRecord, sql);
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            return View("ConstructionPersonnelList", new PlmPersonnelinfoViewModel { ThePersonnelinfoList = consPersonnelList });
        }
        /// <summary>
        /// 人员查看
        /// </summary>
        /// <returns></returns>
        public ActionResult AllPersonnelList()
        {
            string sql = "";
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = 1;
            //每页多少条
            ViewBag.numPerPage = 20;
            var consPersonnelList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(ViewBag.pageNum, ViewBag.numPerPage, "Pi_SectionName,a.Pi_Post", out totalRecord, " Pi_SectionName in (" + Get_JL_JC_ZDJL_SG_SegmentCodes() + ") ");
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            return View(new PlmPersonnelinfoViewModel { ThePersonnelinfoList = consPersonnelList });
        }
        /// <summary>
        /// 人员查看-列表(分页提交)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SplitPageForAllPersonnel()
        {
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = Convert.ToInt32(Request.Form["pageNum"]);
            //每页多少条
            ViewBag.numPerPage = Convert.ToInt32(Request.Form["numPerPage"]);
            ViewBag.iput_name = Request.Form["iput_name"];
            ViewBag.iput_post = Request.Form["iput_post"];

            ViewBag.iput_professsional = Request.Form["iput_professsional"];
            ViewBag.iput_section = Request.Form["rygl_rycx_section"];
            string sql = " 1=1 ";
            if (ViewBag.iput_name != "")
                sql += " and Pi_Name like '%" + ViewBag.iput_name + "%' ";
            if (ViewBag.iput_post != "")
                sql += " and Pi_Post like '%" + ViewBag.iput_post + "%' ";
            if (ViewBag.iput_professsional != "")
                sql += " and Pi_Professional like '%" + ViewBag.iput_professsional + "%' ";
            if (ViewBag.iput_section != "")
            {
                string str = ViewBag.iput_section;
                String[] strArray = null;
                strArray = str.Split(',');
                string strnew = "";
                for (int i = 0; i < strArray.Length-1; i++)
                {
                    strnew += "'" + strArray[i] + "',";
                    
                }

                sql += " and Pi_SectionName in (" + strnew.Trim(',') + ") ";
            }
            else
            {
                sql += " and Pi_SectionName in (" + Get_JL_JC_ZDJL_SG_SegmentCodes() + ") ";
            }


            var consPersonnelList = PlmPersonnelinfoUIRule.GetAllCostplanmainForPage(ViewBag.pageNum, ViewBag.numPerPage, "Pi_UpdateTime", out totalRecord, sql);
            //总条数
            ViewBag.totalcount = totalRecord;
            //总页数
            ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            return View("AllPersonnelList", new PlmPersonnelinfoViewModel { ThePersonnelinfoList = consPersonnelList });
        }
        /// <summary>
        /// 标段信息弹出框
        /// </summary>
        /// <param name="type">考核类型</param>
        /// <param name="ucodes">单位合同号集合</param>
        /// <returns></returns>
        public ActionResult PersonnelSectionUnit()
        {
            return View();
        }
        /// <summary>
        /// 施工人员添加
        /// </summary>
        /// <returns></returns>
        public ActionResult ConstructionPersonnelAdd(string Section)
        {
            var model = new PlmPersonnelinfoViewModel();
            model.ThePersonnelinfoInfo = new PlmPersonnelinfoInfo();
            model.ThePersonnelinfoInfo.Pi_SectionName = Section;

            ProjectUnitInfo uInfo = GetUnitInfoByCode(Section);
            model.ThePersonnelinfoInfo.Pi_UnitID = uInfo.UNIT_ID ;
            model.ThePersonnelinfoInfo.Pi_UnittName = uInfo.UNIT_NAME;
            //TODO:操作人信息、所属施工队信息
            model.ThePersonnelinfoInfo.Pi_UserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
            model.ThePersonnelinfoInfo.Pi_UserName = GetLoginUserRealName;



            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem { Text = "男", Value = "男" });
            list.Add(new SelectListItem { Text = "女", Value = "女" });
            ViewBag.list = list;
            //附件
            var assisId = GenerateRandom();
            var assisIdRet = 0;
            CreateAssistId(PlmPersonnelinfoUIRule, assisId, out assisIdRet);
            ViewBag.AssisId = assisIdRet;
            //获取模块ID
            ViewBag.MoudleID = GetEntityByUrl(Models.PageURL.施工人员管理);
            //附件目录名
            ViewBag.DirWhere = Models.DirName.施工人员管理;
            return View(model);
        }
        /// <summary>
        ///施工人员信息-添加 
        /// 功能：执行添加操作
        /// </summary>
        /// <returns></returns>
        public JsonResult ConstructionPersonnelAddData(PlmPersonnelinfoViewModel vm)
        {
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                vm.ThePersonnelinfoInfo.Pi_ID = Guid.NewGuid().ToString();
                //TODO:操作人信息、所属施工队信息
                vm.ThePersonnelinfoInfo.Pi_UserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
                vm.ThePersonnelinfoInfo.Pi_UserName = GetLoginUserRealName;
                vm.ThePersonnelinfoInfo.Pi_UpdateTime = DateTime.Now;

                var AssistID = Convert.ToInt32(Request.Form["AssistID"]);
                vm.ThePersonnelinfoInfo.Assist_ID = AssistID;
                int safe = PlmPersonnelinfoUIRule.AddPersonnelinfo(vm.ThePersonnelinfoInfo);
            });

            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "添加成功",
                    navTabId = "rygl_sgry_list",
                    rel = "",
                    callbackType = "closeCurrent",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "添加失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        /// <summary>
        /// 施工人员信息-删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult ConstructionPersonnelDelete(string id)
        {
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                int constru = PlmPersonnelinfoUIRule.DeletePersonnelinfo(id);
            });
            dynamic jsonReturn = new ExpandoObject();
            //删除成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "删除成功",
                    navTabId = "rygl_sgry_list",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "删除失败",
                };
            }
            return new JsonResult()
            {
                Data = jsonReturn
            };

        }
        /// <summary>
        /// 安全生产台账-批量删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult ConstructionPersonnelMultiDelete()
        {
            dynamic jsonReturn = new ExpandoObject();
            var ids = base.GetRequestFormValue<string>("ids");
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                int constru = PlmPersonnelinfoUIRule.DeletePersonnelinfoMulti(ids);
            });

            //保存成功
            if (true)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "删除成功",
                    navTabId = "rygl_sgry_list",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "删除失败",
                };
            }
            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        /// <summary>
        /// 施工人员信息——编辑
        /// 功能：根据id加载相对应数据
        /// </summary>
        /// <returns></returns>
        public ActionResult ConstructionPersonnelEdit(Guid id)
        {
            var construtionInfo = PlmPersonnelinfoUIRule.GetPersonnelinfoByID(id);
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem { Text = "男", Value = "男" });
            list.Add(new SelectListItem { Text = "女", Value = "女" });
            ViewBag.list = list;
            //TODO:操作人信息
            construtionInfo.Pi_UserID = GetLoginUserId;
            construtionInfo.Pi_UserName = GetLoginUserRealName;

            //附件
            var commonFileList = CommonFileUIRule.GetCommonFilesByConditon(construtionInfo.Assist_ID, "PlmPersonnelinfo_Rules");//PlmPersonnelinfo_Rules  BizType类型
            ViewBag.AssisId = construtionInfo.Assist_ID;
            ViewBag.FileIds = string.Join(",", commonFileList.Select(t => t.FILE_FILEID));
            ViewBag.DeleteIds = string.Join(",", commonFileList.Select(t => t.FILE_ID));

            //获取模块ID
            ViewBag.MoudleID = GetEntityByUrl(Models.PageURL.施工人员管理);
            //附件目录名
            ViewBag.DirWhere = Models.DirName.施工人员管理;

            return View(new PlmPersonnelinfoViewModel { ThePersonnelinfoInfo = construtionInfo });
        }
        /// <summary>
        /// 施工人员信息-编辑（保存工作） 
        /// 功能：执行保存数据
        /// </summary>
        /// <returns></returns>
        public JsonResult ConstructionPersonnelEditData(PlmPersonnelinfoViewModel vm)
        {
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                vm.ThePersonnelinfoInfo.Pi_UpdateTime = DateTime.Now;
                var AssistID = Convert.ToInt32(Request.Form["AssistID"]);
                vm.ThePersonnelinfoInfo.Assist_ID = AssistID;
                int construction = PlmPersonnelinfoUIRule.UpdatePersonnelinfo(vm.ThePersonnelinfoInfo);
            });

            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "更新成功",
                    navTabId = "rygl_sgry_list",
                    rel = "",
                    callbackType = "closeCurrent",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "更新失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }


        /// <summary>
        /// 施工人员信息——查看
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public ActionResult ConstructionPersonnelDetail(Guid id)
        {
            var ConstructionInfo = PlmPersonnelinfoUIRule.GetPersonnelinfoByID(id);

            //附件
            var commonFileList = CommonFileUIRule.GetCommonFilesByConditon(ConstructionInfo.Assist_ID, "PlmPersonnelinfo_Rules");//PlmPersonnelinfo_Rules  BizType类型
            ViewBag.AssisId = ConstructionInfo.Assist_ID;
            ViewBag.FileIds = string.Join(",", commonFileList.Select(t => t.FILE_FILEID));
            ViewBag.DeleteIds = string.Join(",", commonFileList.Select(t => t.FILE_ID));

            //获取模块ID
            ViewBag.MoudleID = GetEntityByUrl(Models.PageURL.施工人员管理);
            //附件目录名
            ViewBag.DirWhere = Models.DirName.施工人员管理;

            return View(new PlmPersonnelinfoViewModel { ThePersonnelinfoInfo = ConstructionInfo });
        }
        /// <summary>
        /// Excel导出
        /// </summary>
        /// <returns></returns>
        public FileResult Excel(string Section)
        {
            //获取list数据           
          //  var list = PlmPersonnelinfoUIRule.GetAllPersonnelinfo(" Pi_SectionName='" + Section + "' ");
            var list = GetSessionValue<List<PlmPersonnelinfoInfo>>(RYGL_SGRY);
            //创建Excel文件的对象
            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
            //添加一个sheet
            NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
            //列宽度
            sheet1.SetColumnWidth(0, 5 * 256);
            sheet1.SetColumnWidth(1, 15 * 256);
            sheet1.SetColumnWidth(2, 15 * 256);
            sheet1.SetColumnWidth(3, 15 * 256);
            sheet1.SetColumnWidth(4, 15 * 256);
            sheet1.SetColumnWidth(5, 15 * 256);
            sheet1.SetColumnWidth(6, 15 * 256);
            sheet1.SetColumnWidth(7, 15 * 256);
            sheet1.SetColumnWidth(8, 15 * 256);
            sheet1.SetColumnWidth(9, 15 * 256);
            sheet1.SetColumnWidth(10, 15 * 256);
            //设置第一行
            IRow row0 = sheet1.CreateRow(0);
            //行高
            row0.Height = 30 * 20;
            //合并单元格
            sheet1.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10));
            //创建单元格
            CreateCell(row0, 0, Getcellstyle(book, "center", false, 14, 300), "施工人员信息");
            //设置第二行
            IRow row1 = sheet1.CreateRow(1);
            row1.Height = 20 * 20;
            sheet1.AddMergedRegion(new CellRangeAddress(1, 1, 0, 4));
            sheet1.AddMergedRegion(new CellRangeAddress(1, 1, 5, 10));
            CreateCell(row1, 0, Getcellstyle(book, "left", false, 10, 600), "标段：" + Section);
            string uName = "";
            if (list.Count > 0)
                uName = list[0].Pi_UnittName;
            CreateCell(row1, 5, Getcellstyle(book, "right", false, 10, 600), "单位：" + uName);
            //给sheet1添加第三行的头部标题
            NPOI.SS.UserModel.IRow row2 = sheet1.CreateRow(2);
            row2.Height = 20 * 20;
            CreateCell(row2, 0, Getcellstyle(book, "center", true, 10, 600), "序号");
            CreateCell(row2, 1, Getcellstyle(book, "center", true, 10, 600), "姓名");
            CreateCell(row2, 2, Getcellstyle(book, "center", true, 10, 600), "性别");
            CreateCell(row2, 3, Getcellstyle(book, "center", true, 10, 600), "年龄");
            CreateCell(row2, 4, Getcellstyle(book, "center", true, 10, 600), "身份证号");
            CreateCell(row2, 5, Getcellstyle(book, "center", true, 10, 600), "职位");
            CreateCell(row2, 6, Getcellstyle(book, "center", true, 10, 600), "职称");
            CreateCell(row2, 7, Getcellstyle(book, "center", true, 10, 600), "联系电话");
            CreateCell(row2, 8, Getcellstyle(book, "center", true, 10, 600), "邮箱");
            CreateCell(row2, 9, Getcellstyle(book, "center", true, 10, 600), "执业证书类型");
            CreateCell(row2, 10, Getcellstyle(book, "center", true, 10, 600), "执业证书编号");

            //将数据逐步写入sheet1各个行
            for (int i = 0; i < list.Count; i++)
            {
                NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 3);
                CreateCell(rowtemp, 0, Getcellstyle(book), (i + 1).ToString());
                CreateCell(rowtemp, 1, Getcellstyle(book), list[i].Pi_Name);
                CreateCell(rowtemp, 2, Getcellstyle(book), list[i].Pi_Sex);
                CreateCell(rowtemp, 3, Getcellstyle(book), list[i].Pi_Age.ToString());
                CreateCell(rowtemp, 4, Getcellstyle(book), list[i].Pi_IDNo);
                CreateCell(rowtemp, 5, Getcellstyle(book), list[i].Pi_Post);
                CreateCell(rowtemp, 6, Getcellstyle(book), list[i].Pi_Professional);
                CreateCell(rowtemp, 7, Getcellstyle(book), list[i].Pi_Phone);
                CreateCell(rowtemp, 8, Getcellstyle(book), list[i].Pi_Email);
                CreateCell(rowtemp, 9, Getcellstyle(book), list[i].Pi_License);
                CreateCell(rowtemp, 10, Getcellstyle(book), list[i].Pi_LicenseNum);
            }
            // 写入到客户端 
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            book.Write(ms);
            ms.Seek(0, SeekOrigin.Begin);
            string fileName = HttpUtility.UrlEncode("施工人员信息.xls", Encoding.GetEncoding("UTF-8"));
            return File(ms, "application/vnd.ms-excel", fileName);

        }
        #region Excel导入
        /// <summary>
        /// Excel导入
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public JsonResult ImportExcelFile(HttpPostedFileBase FileData, string Section)
        {
            //string infor = "";
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                if (FileData != null)
                {
                    string tempFileName = FileData.FileName;
                    string fileExt = Path.GetExtension(tempFileName).ToLower();
                    string fileName = Guid.NewGuid().ToString() + fileExt;

                    string tempPath = "/TempleterFilePath";
                    if (!tempPath.EndsWith("/"))
                        tempPath += "/";
                    tempPath = Server.MapPath(tempPath);
                    if (!Directory.Exists(tempPath))
                        Directory.CreateDirectory(tempPath);
                    tempPath = Path.Combine(tempPath, fileName);
                    FileData.SaveAs(tempPath);
                    if (string.IsNullOrWhiteSpace(tempPath) || !System.IO.File.Exists(tempPath))
                    {
                        throw new Exception("导入文件不存在");
                    }
                    HSSFWorkbook hssfworkbook;
       
                    //读取文件流
                    using (FileStream fs = System.IO.File.OpenRead(tempPath))
                    {
                        hssfworkbook = new HSSFWorkbook(fs);
                        //获取第一个工作簿
                        NPOI.SS.UserModel.ISheet sheet = hssfworkbook.GetSheetAt(0);
                        {

                            //获取第一行
                            IRow headerRow = sheet.GetRow(0);
                            //列数
                            int cellCount = headerRow.LastCellNum;
                            //行数
                            int rowCount = sheet.LastRowNum;
                            //循环行
                            for (int i = 1; i <= rowCount; i++)
                            {
                                IRow row = sheet.GetRow(i);
                                //人员信息
                                PlmPersonnelinfoInfo info = new PlmPersonnelinfoInfo();
                                info.Pi_ID = Guid.NewGuid().ToString();
                                info.Pi_SectionName = Section;
                                info.Pi_UpdateTime = DateTime.Now;
                                ProjectUnitInfo uInfo = GetUnitInfoByCode(Section);
                                info.Pi_UnitID = uInfo.UNIT_ID;
                                info.Pi_UnittName = uInfo.UNIT_NAME;

                                //TODO:操作人信息、所属施工队信息
                                info.Pi_UserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
                                info.Pi_UserName = GetLoginUserRealName;


                                //读取该行信息
                                info.Pi_Name = GetCellValue(row.GetCell(0));
                                info.Pi_Sex = GetCellValue(row.GetCell(1));
                                if (GetCellValue(row.GetCell(2)) != "")
                                    info.Pi_Age = Convert.ToInt32(GetCellValue(row.GetCell(2)));
                                info.Pi_IDNo = GetCellValue(row.GetCell(3));
                                info.Pi_Post = GetCellValue(row.GetCell(4));
                                info.Pi_Professional = GetCellValue(row.GetCell(5));
                                info.Pi_Phone = GetCellValue(row.GetCell(6));
                                info.Pi_Email = GetCellValue(row.GetCell(7));
                                info.Pi_License = GetCellValue(row.GetCell(8));
                                info.Pi_LicenseNum = GetCellValue(row.GetCell(9));
                                //向数据库插入数据 
                                PlmPersonnelinfoUIRule.AddPersonnelinfo(info);
                            }

                        }
                    }

                    //删除临时文件
                    System.IO.File.Delete(tempPath);
                }
            });
            dynamic jsonReturn = new ExpandoObject();
            //保存成功
            if (isScuess)
            {

                jsonReturn = new
                {
                    statusCode = "200",
                    message = "导入成功",
                    navTabId = "",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };

            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "导入失败",
                };
            }
            return new JsonResult()
            {
                Data = jsonReturn
            };

        }
        //public JsonResult ImportExcelFile(int[] datas, string Section)
        //{
           
        //    var isScuess = TryCatchCommand.TryExec(() =>
        //    {
        //        if (datas != null)
        //        {
        //            HSSFWorkbook hssfworkbook;
        //            var bytes = datas.ToList().ConvertAll(x => (byte)x).ToArray();
        //            //读取文件流
        //            using (Stream file = new MemoryStream(bytes))
        //            {
        //                hssfworkbook = new HSSFWorkbook(file);
        //            }
        //            //获取第一个工作簿
        //            NPOI.SS.UserModel.ISheet sheet = hssfworkbook.GetSheetAt(0);
        //            {
                       
        //                     //获取第一行
        //                     IRow headerRow = sheet.GetRow(0);
        //                     //列数
        //                     int cellCount = headerRow.LastCellNum;
        //                     //行数
        //                     int rowCount = sheet.LastRowNum;
        //                     //循环行
        //                     for (int i = 1; i <= rowCount; i++)
        //                     {
        //                         IRow row = sheet.GetRow(i);
        //                         //人员信息
        //                         PlmPersonnelinfoInfo info = new PlmPersonnelinfoInfo();
        //                         info.Pi_ID = Guid.NewGuid().ToString();
        //                         info.Pi_SectionName = Section;
        //                         info.Pi_UpdateTime = DateTime.Now;
        //                         ProjectUnitInfo uInfo = GetUnitInfoByCode(Section);
        //                         info.Pi_UnitID = uInfo.UNIT_ID;
        //                         info.Pi_UnittName = uInfo.UNIT_NAME;

        //                         //TODO:操作人信息、所属施工队信息
        //                         info.Pi_UserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
        //                         info.Pi_UserName = GetLoginUserRealName;


        //                         //读取该行信息
        //                         info.Pi_Name = GetCellValue(row.GetCell(0));
        //                         info.Pi_Sex = GetCellValue(row.GetCell(1));
        //                         if (GetCellValue(row.GetCell(2)) != "")
        //                             info.Pi_Age = Convert.ToInt32(GetCellValue(row.GetCell(2)));
        //                         info.Pi_IDNo = GetCellValue(row.GetCell(3));
        //                         info.Pi_Post = GetCellValue(row.GetCell(4));
        //                         info.Pi_Professional = GetCellValue(row.GetCell(5));
        //                         info.Pi_Phone = GetCellValue(row.GetCell(6));
        //                         info.Pi_Email = GetCellValue(row.GetCell(7));
        //                         info.Pi_License = GetCellValue(row.GetCell(8));
        //                         info.Pi_LicenseNum = GetCellValue(row.GetCell(9));
        //                         //向数据库插入数据 
        //                         PlmPersonnelinfoUIRule.AddPersonnelinfo(info);
        //                     }
                        
        //            }
        //        }
        //    });
        //    dynamic jsonReturn = new ExpandoObject();
        //    //保存成功
        //    if (isScuess)
        //    {
               
        //            jsonReturn = new
        //            {
        //                statusCode = "200",
        //                message = "导入成功",
        //                navTabId = "",
        //                rel = "",
        //                callbackType = "",
        //                forwardUrl = "",
        //                confirmMsg = ""
        //            };
               
        //    }
        //    else
        //    {
        //        jsonReturn = new
        //        {
        //            statusCode = "300",
        //            message = "导入失败",
        //        };
        //    }
        //    return new JsonResult()
        //    {
        //        Data = jsonReturn
        //    };

        //}


        #endregion


    }
}
